﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;
using System.Collections;

namespace Advisor.Entities
{
    public class RiskProjectMappingsDAO
    {
        private Users m_User;
        public RiskProjectMappingsDAO(Users user)
        {
            this.m_User = user;
        }

          /// <summary>
        /// Retorna todas os registros da tabela RiskProjectMappings. 
        /// </summary>
        /// <param name="column"></param>
        /// <param name="maximumRows"></param>
        /// <param name="startRowIndex"></param>
        /// <returns></returns>
        internal IList GetRiskProjectMappings(string column, int maximumRows, int startRowIndex)
        {
            ISession session = NHibernateSession.GetSession();
            string sql = "FROM RISKPROJECTMAPPINGS as riskProjectMappings";

            //Ordenação
            if (!String.IsNullOrEmpty(column))
            {
                sql += " ORDER BY riskProjectMappings." + column;
            }
            IQuery query = session.CreateQuery(sql);

            //Paginando
            query.SetFirstResult(startRowIndex);
            query.SetMaxResults(maximumRows);

            return query.List();
        }

        /// <summary>
        ///  Método para inserir um RiskProjectMapping no banco. 
        /// </summary>
        /// <param name="history"></param>
        internal void InsertMemberProject(IdRiskprojectmappings riskProjectMapping)
        {
            ISession session = NHibernateSession.GetSession();
            session.Save(riskProjectMapping);
            session.Close();
        }

        /// <summary>
        /// Retorna uma instância da tabela RiskProjectMappings passando o id;
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        internal IdRiskprojectmappings GetRiskProjectMapping(int id)
        {
            ISession session = NHibernateSession.GetSession();
            return (IdRiskprojectmappings)session.Get(typeof(IdRiskprojectmappings), id);
        }

        /// <summary>
        /// Remove um RiskProjectMapping do banco
        /// </summary>
        /// <param name="history"></param>
        internal void DeleteRiskProjectMapping(IdRiskprojectmappings riskProjectMapping)
        {
            ISession sessions = NHibernateSession.GetSession();
            sessions.Delete(riskProjectMapping);
            sessions.Close();
        }

        /// <summary>
        /// Atualiza um RiskProjectMapping do banco. 
        /// </summary>
        /// <param name="history"></param>
        public void UpdateRiskProjectMapping(IdRiskprojectmappings riskProjectMapping)
        {
            ISession session = NHibernateSession.GetSession();
            session.Update(riskProjectMapping);
            session.Flush();
            session.Close();
        }

    } 
    }

